Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New Dark Scheme Part 2 #3317

Closed
wants to merge 16 commits into from

Conversation

alifafaruk
Copy link
Contributor

@alifafaruk alifafaruk commented Apr 24, 2020

Dark mode support
fixes #2407

@lucasortizny @Jen-Lopez and I worked on the dark mode feature for the website. We implemented a toggle button, where the user can turn dark mode on/off. We did a pull request earlier, but it had multiple merge conflicts that we weren't able to fix. So we closed that. We fixed the issues on our end and now it works!

Screen Shot 2020-04-24 at 5 00 40 PM

Screen Shot 2020-04-24 at 12 58 42 PM

@stephanegigandet
Copy link
Contributor

Hi @alifafaruk ! Thank you for the PR!

The dark mode looks very good, but instead of adding a site specific toggle, I think it would make much more sense to just use the CSS prefers-color-scheme, as @teolemon suggested in the bug #2407

That way we can avoid the 2 javascript scripts that will block the page rendering for all users until they load, and we can have a pure CSS solution.

Also it would be great to put the CSS styles inside the SCSS ( in the /scss/ directory) so that they get processed along with the rest of the CSS styles.

cc @hangy

@teolemon
Copy link
Member

teolemon commented May 3, 2020

@@ -0,0 +1,30 @@
var stylesheet = document.styleSheets[3]; // dark-mode stylesheet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line of code is unrealible because order of stylesheets might be different on different pages and changed by newer code changes. If you want to use document.styleSheets, at least use title attribute, like shown in first example here

// Before page renders, check if page is in darkmode.
// Otherwise, it will load regular styles before dark style.
let dark = localStorage.getItem('darkMode');
var sheet = document.styleSheets[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same issue as in darkMode.js

@GendelfLugansk
Copy link
Contributor

It seems like prefers-color-scheme requires user to activate dark theme on OS level. Correct me if I'm wrong. In this case I'm not sure if it's better

cc @stephanegigandet @teolemon @hangy

@GendelfLugansk

This comment has been minimized.

@GendelfLugansk
Copy link
Contributor

Also, it seems like it might be possible to share "dark mode" setting across different domains but this might be complex to implement. I think that would require changes to perl code, docker config and nginx/apache config on production site. I don't have perl expertise to give more detailed advice.

@hangy
Copy link
Member

hangy commented May 3, 2020

It seems like prefers-color-scheme requires user to activate dark theme on OS level. Correct me if I'm wrong. In this case I'm not sure if it's better

It sounds like a good idea to default to the dark mode, if someone has selected it, though. This guide explains that the media query can also be done from JS.

Also, it seems like it might be possible to share "dark mode" setting across different domains but this might be complex to implement. I think that would require changes to perl code, docker config and nginx/apache config on production site.

Changing some JavaScript should suffice, if I understand the blog post correctly. However, I wonder if we need localStorage for this. To no waste too much cookie storage, one could just set a d=1 cookie to store enabled/changed dark mode setting in a cross-subdomain cookie.

html/js/darkMode.js Outdated Show resolved Hide resolved
Copy link
Member

@hangy hangy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the new JS/CSS files to gulpfile.js and then include them from the dist/js/dist/css directory, so that we can load the minified versions?

@@ -6090,7 +6090,13 @@ $options{favicons}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" integrity="sha256-FdatTf20PQr/rWg+cAKfl6j4/IY3oohFAJ7gVC3M34E=" crossorigin="anonymous">
<link rel="search" href="$formatted_subdomain/cgi/opensearch.pl" type="application/opensearchdescription+xml" title="$Lang{site_name}{$lang}">
$header
<!-- Dark Mode -->
<link rel="stylesheet" href="$static_subdomain/css/darkMode.css">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically makes dark mode the default - Might introduce unwanted behaviour if JavaScript is disabled. cc @stephanegigandet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dark mode should not be the default.

Copy link
Contributor

@GendelfLugansk GendelfLugansk May 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test in all browsers but in Chromium adding disabled="true" to link disables stylesheet. I think this should work in other browsers as well. JS code of this PR is based on disabled property and MDN says it's supported everywhere except IE (support is unknown)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test in all browsers but in Chromium adding disabled="true" to link disables stylesheet. I think this should work in other browsers as well. JS code of this PR is based on disabled property and MDN says it's supported everywhere except IE (support is unknown)

Right, but there are some extensions that completely disable Javascript execution. In that case dark mode would be the default. Consider adding disabled="true" here and changing it in JS.

@stephanegigandet
Copy link
Contributor

It seems like prefers-color-scheme requires user to activate dark theme on OS level. Correct me if I'm wrong. In this case I'm not sure if it's better

I don't know either. Is there some research on dark mode users? Do they turn it on or off depending on ambient light? Does it make sense to turn it on and off depending on the web sites users visit?

I was under the impression that it was more of a "global" preference that is valid accross sites and times: you either want dark mode all the time, or you don't. So you set it once in the OS preference, and then hopefully web sites have styles that match your preference.

@GendelfLugansk
Copy link
Contributor

I was under the impression that it was more of a "global" preference that is valid accross sites and times: you either want dark mode all the time, or you don't. So you set it once in the OS preference, and then hopefully web sites have styles that match your preference.

The thing is, when I google "Chrome dark mode", I see this article which implies that dark mode is supported only in Win 10+ and MacOS 10.14+. As Ubuntu 18.04 user, I don't think I can enable it. So for various Linux users toggle might be useful. Toggle can be combined with prefers-color-scheme, as was suggested above

@VaiTon
Copy link
Member

VaiTon commented May 9, 2020

The thing is, when I google "Chrome dark mode", I see this article which implies that dark mode is supported only in Win 10+ and MacOS 10.14+. As Ubuntu 18.04 user, I don't think I can enable it. So for various Linux users toggle might be useful. Toggle can be combined with prefers-color-scheme, as was suggested above

I agree. Other sites (eg. stackoverflow, youtube, etc.) are using a site-specific switch and eventually we could add the "system settings" one.

@alifafaruk
Copy link
Contributor Author

Hi all! Thank you for taking the time to look into the pull request. My group (@Jen-Lopez and @lucasortizny) and I are new to web development and are unfamiliar with the mechanics of how to implement a prefers-color-scheme. We will be fixing the CSS to fix the bugs.

@teolemon teolemon added CSS 🎨 Design foundation Foundation is the CSS framework of Open Food Facts. HTML labels May 10, 2020
@stephanegigandet
Copy link
Contributor

Hi Everyone, just wondering if there is still some work being done / to do on this PR?

@teolemon
Copy link
Member

teolemon commented Jun 1, 2020

poke @alifafaruk @VaiTon

@VaiTon
Copy link
Member

VaiTon commented Jun 1, 2020

poke @alifafaruk @VaiTon

Cannot push to branch :)

@alifafaruk
Copy link
Contributor Author

Hi, we fixed all the style changes requested for dark mode. We also fixed bugs that were present. However, we don't know how to implement "prefers-color-scheme," so the method used to implement dark mode is still a toggle. If someone could help us change it to a "prefers-color-scheme" method, that would be great!

@GendelfLugansk
Copy link
Contributor

This is still an issue:
screenshot
"Android apk" is still unreadable:
screenshot
Not sure about this wide border around each tag (if others are ok with it, it's fine with me):
screenshot
This is still an issue (go to "Charts and maps", choose "Energy" for horizontal axis and click "generate graph"):
screenshot

@@ -6090,7 +6090,13 @@ $options{favicons}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" integrity="sha256-FdatTf20PQr/rWg+cAKfl6j4/IY3oohFAJ7gVC3M34E=" crossorigin="anonymous">
<link rel="search" href="$formatted_subdomain/cgi/opensearch.pl" type="application/opensearchdescription+xml" title="$Lang{site_name}{$lang}">
$header
<!-- Dark Mode -->
<link rel="stylesheet" href="$static_subdomain/css/darkMode.css">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add disabled="true" to link tag

@teolemon
Copy link
Member

Good news, the dark mode compatible APK logo is merged, and available in prod

Copy link
Contributor

@GendelfLugansk GendelfLugansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some parts are hard to read

This on the left, when user is logged in:

screenshot

This is the bottom of page:

screenshot

This light block (can be found at http://world.productopener.localhost/category/dairies):

screenshot

Also, edit page (i.e. http://world.productopener.localhost/cgi/product.pl?type=edit&code=3908801793077) has a lot of light-colored blocks:

screenshot

Everything else looks good to me

@Jen-Lopez
Copy link

I fixed the "Edit a Product" Page and went throughout the site to fix more css bugs. Since the new Android image is available in production and is dark mode aware, this issue should be resolved. However, I was unable to fix the floating WebLinks block in "dairies" since there is no id/class associated with it to change the styling. What page should I look at to add an ID to the element? Also, if there are any changes to be made or any suggestions, please let me know.

@sonarcloud
Copy link

sonarcloud bot commented Jul 27, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@teolemon
Copy link
Member

This PR has merge conflicts.

@teolemon teolemon changed the title New Dark Scheme Part 2 feat: New Dark Scheme Part 2 Feb 14, 2022
@CloCkWeRX
Copy link
Contributor

TODO items

@CloCkWeRX
Copy link
Contributor

Did a dark friendly (and light friendly) revamp of the logo
android-apk

@teolemon
Copy link
Member

We just deployed a new design, but without dark mode so far.

@stephanegigandet
Copy link
Contributor

We deployed a redesign of the https://world.openfoodfacts.org website, so sadly we won't be able to deploy this PR.
Sorry about that and thank you for your work @alifafaruk @lucasortizny and @Jen-Lopez .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Dark mode 🎨 Design foundation Foundation is the CSS framework of Open Food Facts. HTML 💥 Merge Conflicts 💥 Merge Conflicts ⭐ top pull request Top pull request.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

NEW DESIGN - Dark mode support
9 participants